package com.pi.smart.wxmini.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.pi.base.dto.result.AppResult;
import com.pi.base.enumerate.file.FileSource;
import com.pi.http.base.controller.BaseController;
import com.pi.uc.service.UcUserService;

@RequestMapping("/pic/")
@RestController
public class PicController extends BaseController{

  @Autowired
  private UcUserService userService;
  @PostMapping("/upload")
  public AppResult updateUserAvatar(MultipartFile file) throws Exception{
    String url = userService.uploadUserPic(file, FileSource.USER_FEEDBACK, getLoginUserId());
    long id = System.currentTimeMillis();
    JSONObject json = new JSONObject();
    json.put("key", url);
    json.put("id", id);
    return AppResult.newSuccessResult(json);
  }
}
